﻿using System;
using System.Collections.Generic;
using System.Web;
namespace FTchina.Library
{
    /// <summary>
    ///MasterHelper 的摘要说明
    /// </summary>
    public class MasterHelper
    {
        public MasterHelper()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }

        /// <summary>
        /// 判断用户是否登陆系统
        /// </summary>

        public static Boolean IsLogin
        {
            get
            {
                int t = 999;
                try
                {
                    t = DateTime.Now.Subtract(Convert.ToDateTime(LoginTime)).Days;
                }
                catch (Exception er)
                {
                    t = 999;
                }
                return t < 1;
            }
        }

        /// <summary>
        /// 登录用户ID,每次登陆随机产生，MD5加密后保存
        /// </summary>
        public static string MasterID
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "MasterID", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "MasterID", SecurityHelper.Encrypt(value));
            }
        }


        /// <summary>
        /// 登陆用户名称ID
        /// </summary>
        public static string MasterName
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "MasterName", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "MasterName", SecurityHelper.Encrypt(value));
            }
        }


        /// <summary>
        /// 登陆用户昵称
        /// </summary>
        public static string Nickname
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "Nickname", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "Nickname", SecurityHelper.Encrypt(value));
            }
        }


        /// <summary>
        /// 用户权限
        /// </summary>
        public static string MasterPower
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "MasterPower", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "MasterPower", SecurityHelper.Encrypt(value));
            }
        }
        /// <summary>
        /// 用户权限名称
        /// </summary>
        public static string MasterPowerName
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "MasterPowerName", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "MasterPowerName", SecurityHelper.Encrypt(value));
            }
        }


        /// <summary>
        /// 登陆用户进行操作记录ID
        /// </summary>
        public static string Luruid
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "Luruid", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "Luruid", SecurityHelper.Encrypt(value));
            }
        }



        /// <summary>
        /// 客户端版本
        /// </summary>
        public static string ClientType
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "ClientType", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "ClientType", SecurityHelper.Encrypt(value));
            }
        }
        /// <summary>
        /// 客户端版本
        /// </summary>
        public static string ClientTitle
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "ClientTitle", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "ClientTitle", SecurityHelper.Encrypt(value));
            }
        }
        /// <summary>
        /// 登录时间
        /// </summary>
        public static string LoginTime
        {
            get
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                return SecurityHelper.Decrypt(ih.ReadString("user", "LoginTime", ""));
            }
            set
            {
                FTchina.Library.IniHelper ih = new FTchina.Library.IniHelper();
                ih.UpdateINIFile("user", "LoginTime", SecurityHelper.Encrypt(value));
            }
        }
        /// <summary>
        /// 通过用户id获取用户名
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetUserNameById(string id)
        {

            return shujuku.GetValueByKey("master_name", "master", "link='" + id + "'");
        }


        /// <summary>
        /// 获取格式化用户id名称,如  13|魏宝辉
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static string GetFormatUidName()
        {
            return Luruid + "|" + GetUserNameById(Luruid);
        }


        /// <summary>
        /// 设置用户登录IP
        /// </summary>
        private static String _LoginIP;
        public static String LoginIP
        {
            get { return _LoginIP; }
            set { _LoginIP = value; }
        }
    }

}
